/*
 * @Author: 郑俊标
 * @Date: 2024-06-20 16:40:13
 * @LastEditors: 郑俊标
 * @LastEditTime: 2024-07-23 21:12:40
 * @Description: setting -vuex
 */

import defaultSettings from '@/settings';

// 全局默认配置
const { sideTheme, showSettings, topNav, tagsView,
    fixedHeader, sidebarLogo, dynamicTitle
} = defaultSettings;

// 用户本地自定义配置
const storageSetting = JSON.parse(localStorage.getItem('layout-setting')) || "";

const state = {
    title: '',
    theme: storageSetting.theme || '#409EFF',
    sideTheme: storageSetting.sideTheme || sideTheme,
    topNav: storageSetting.topNav || topNav,
    tagsView: storageSetting.tagsView || tagsView,
    fixedHeader: storageSetting.fixedHeader || fixedHeader,
    sidebarLogo: storageSetting.sidebarLogo || sidebarLogo,
    dynamicTitle: storageSetting.dynamicTitle || dynamicTitle,
};

const mutations =  {
    CHANGE_SETTING(state, { key, value }) {
        if (state.hasOwnProperty(key)) {
            state[key] = value;
        }
    }
}

const actions = {
    setTitle: ({ commit }, title) => {
        state.title = title;
    },
    // 修改布局设置
    changeSetting({commit}, data) {
        commit('CHANGE_SETTING',data)
    }
}

export default {
    namespaced: true,
    state,
    actions,
    mutations
}